package com.jmx.yp.dao;

import org.apache.log4j.Logger;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import java.util.List;

/**
 * IBaseDao
 * @author jenny
 * Sep 5, 2007
 */
public class BaseDaoImpl extends SqlSessionDaoSupport implements IBaseDao {
	
	private static Logger log = (Logger)Logger.getLogger(BaseDaoImpl.class);
	
	private int pageSize;
	
	public void setPageSize(int pageSize){
		this.pageSize = pageSize;
	}
	
	public int getPageSize(){
		return pageSize;
	}
		
	/**
	 * 
	 * @param id
	 * @return
	 */
	public Object getObject(String schema, Object id){
		if(id != null)
			return getSqlSession().selectOne(schema, id);
		else
			return getSqlSession().selectOne(schema);
	}
	
	public List getList(String schema, Object id){
		
		if(id != null)
			return getSqlSession().selectList(schema, id);
		else
			return getSqlSession().selectList(schema); 
	}
	
	public void saveObject(String schema, Object obj){
		getSqlSession().insert(schema, obj);
	}
    
	/**
	 * 更新对象
	 */
	public void updateObject(String schema, Object obj){
		getSqlSession().update(schema, obj);
	}
	
	/**
	 * 删除对象
	 * @param schema
	 * @param obj
	 */
	public void deleteObject(String schema, Object obj){
		if(obj == null)
			getSqlSession().delete(schema);
		else
			getSqlSession().delete(schema, obj);
	}
}
